home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / bserverdir / sources / clients / fireworks.c < prev    next >
C/C++ Source or Header  |  1994-12-08  |  5KB  |  236 lines

  1. ;/*
  2. sc Fireworks.c IGNORE=73 DATA=FAR NMINC STRMERGE NOSTKCHK IGNORE=73 STRUCTUREEQUIVALENCE NOSTDIO
  3. Slink from LIB:c.o Fireworks.o to //Clients/Fireworks LIB LIB:scm.lib LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD NOICONS STRIPDEBUG
  4. delete Fireworks.o
  5. quit
  6.  
  7.  Fireworks 1.2  (Client for BServer)
  8.  
  9.  Copyright © 1994 by Stefano Reksten of 3AM - The Three Amigos!!!
  10.  All rights reserved.
  11. */
  12.  
  13. #include <exec/types.h>
  14. #include <exec/memory.h>
  15.  
  16. #include <clib/exec_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/graphics_protos.h>
  19. #include <clib/alib_protos.h>
  20. #include <time.h>
  21. #include <math.h>
  22.  
  23. #include "/include/client.h"
  24.  
  25. struct IntuitionBase *IntuitionBase;
  26. struct GfxBase *GfxBase;
  27.  
  28. struct DisplayIDInformation *dinfo;
  29.  
  30. struct Screen *scr1, *scr2;
  31.  
  32. #define MAXFWKS 10
  33. #define BITSPERFWK 10
  34. #define TOTALFWKS MAXFWKS * BITSPERFWK
  35. #define SCRDEPTH 3
  36.  
  37. struct Fire {
  38.     WORD X, Y;
  39.     WORD OldX, OldY;
  40.     WORD VelX;
  41.     WORD VelY;
  42.     BOOL Active;
  43.     UWORD ExpTime;
  44.     BOOL Exploded;
  45.     UBYTE Color;
  46.     } Fireworks[TOTALFWKS];
  47.  
  48. extern ULONG RangeSeed;
  49. UWORD swidth, sheight, maxw, maxh;
  50. BOOL lace;
  51.  
  52.  
  53. void SetAllFireworks( void )
  54. {
  55. register UBYTE n;
  56.  
  57. for ( n = 0; n < TOTALFWKS; n++ )
  58.     {
  59.     Fireworks[n].X = 0;
  60.     Fireworks[n].Y = 0;
  61.     Fireworks[n].Active = FALSE;
  62.     }
  63. }
  64.  
  65.  
  66. void MoveAllFireworks( struct Screen *scr )
  67. {
  68. register UBYTE n, m;
  69. register struct RastPort *rp;
  70. register UBYTE color;
  71.  
  72. rp = &(scr->RastPort);
  73.  
  74. for ( n = 0; n < TOTALFWKS; n += BITSPERFWK )
  75.     {
  76.     if ( !(Fireworks[n].Active) )
  77.         {
  78.         Fireworks[n].OldX = Fireworks[n].X;
  79.         Fireworks[n].OldY = Fireworks[n].Y;
  80.         Fireworks[n].X = RangeRand( maxw );
  81.         Fireworks[n].Y = maxh - 1;
  82.         Fireworks[n].VelX = ( RangeRand( 17 ) - 8 );
  83.         Fireworks[n].VelY = ( lace ? -30-RangeRand(45) : -20-RangeRand(40) );
  84.         Fireworks[n].Active = TRUE;
  85.         Fireworks[n].Exploded = FALSE;
  86.         Fireworks[n].ExpTime = RangeRand( 15 ) + 15;
  87.         Fireworks[n].Color = RangeRand( 3 ) + 1;
  88.         }
  89.     }
  90.  
  91. for ( n = 0; n < TOTALFWKS; n++ )
  92.     {
  93.     if ( Fireworks[n].Active )
  94.         {
  95.         Move( rp, Fireworks[n].X >> 3, Fireworks[n].Y >> 3 );
  96.         Fireworks[n].X += Fireworks[n].VelX;
  97.         Fireworks[n].Y += Fireworks[n].VelY;
  98.         Fireworks[n].VelY++;
  99.  
  100.         if ( Fireworks[n].X < 0 || Fireworks[n].X >= maxw )
  101.             Fireworks[n].Active = FALSE;
  102.  
  103.         if ( Fireworks[n].Y < 0 || Fireworks[n].Y >= maxh )
  104.             Fireworks[n].Active = FALSE;
  105.  
  106.         if ( Fireworks[n].Active )
  107.             {
  108.             if ( !Fireworks[n].Exploded || Fireworks[n].ExpTime % 5 )
  109.                 {
  110.                 SetAPen( rp, Fireworks[n].Color );
  111.                 Draw( rp, Fireworks[n].X >> 3, Fireworks[n].Y >> 3 );
  112.                 }
  113.  
  114.             if ( !Fireworks[n].Exploded )
  115.                 {
  116.                 if ( --Fireworks[n].ExpTime == 0 )
  117.                     {
  118.                     Fireworks[n].Exploded = TRUE;
  119.                     color = RangeRand( 3 ) + 1;
  120.                     Fireworks[n].Color = color;
  121.                     for ( m = 1; m < BITSPERFWK; m++ )
  122.                         {
  123.                         Fireworks[n+m].X = Fireworks[n].X;
  124.                         Fireworks[n+m].Y = Fireworks[n].Y;
  125.                         Fireworks[n+m].VelX = Fireworks[n].VelX + RangeRand( 15 ) - 7;
  126.                         Fireworks[n+m].VelY = Fireworks[n].VelY + RangeRand( 7 ) - 3;
  127.                         Fireworks[n+m].Exploded = TRUE;
  128.                         Fireworks[n+m].Active = TRUE;
  129.                         Fireworks[n+m].Color = color;
  130.                         Fireworks[n+m].ExpTime = m;
  131.                         }
  132.                     }
  133.                 }
  134.             else
  135.                 {
  136.                 if ( RangeRand( ++Fireworks[n].ExpTime ) >= 70 )
  137.                     Fireworks[n].Active = FALSE;
  138.                 }
  139.             }
  140.         }
  141.     }
  142.  
  143. WaitTOF();
  144. ScreenToFront( scr );
  145. SpritesOff();
  146. SetRast( (scr == scr1 ? &(scr2->RastPort) : &(scr1->RastPort)), 0 );
  147. }
  148.  
  149.  
  150. void Blank( void )
  151. {
  152. BOOL success = FALSE;
  153. UBYTE n, r, g, b;
  154. struct Screen *activescr;
  155.  
  156. struct Rectangle *rect;
  157.  
  158. rect = GETTXTOSCANRECT(dinfo);
  159.  
  160. swidth = RECTANGLEWIDTH(rect);
  161. sheight = RECTANGLEHEIGHT(rect);
  162. maxw = swidth << 3;
  163. maxh = sheight << 3;
  164. lace = DISPLAYID(dinfo) & LACE;
  165.  
  166. scr1 = scr2 = NULL;
  167.  
  168. if ( (scr1 = OpenScreenTags( NULL,
  169.         SA_Width, swidth,
  170.         SA_Height, sheight,
  171.         SA_Depth, SCRDEPTH,
  172.         SA_Type, CUSTOMSCREEN,
  173.         SA_Quiet, TRUE,
  174.         SA_DisplayID, DISPLAYID(dinfo),
  175.         SA_Overscan, OSCAN_TEXT,
  176.         TAG_END ) ) &&
  177.  (scr2 = OpenScreenTags( NULL,
  178.         SA_Width, swidth,
  179.         SA_Height, sheight,
  180.         SA_Depth, SCRDEPTH,
  181.         SA_Type, CUSTOMSCREEN,
  182.         SA_Quiet, TRUE,
  183.         SA_DisplayID, DISPLAYID(dinfo),
  184.         SA_Overscan, OSCAN_TEXT,
  185.         TAG_END ) ) )
  186.     {
  187.     success = TRUE;
  188.     activescr = scr1;
  189.  
  190.     SetRGB4( &scr1->ViewPort, 0, 0, 0, 0 );
  191.     SetRGB4( &scr2->ViewPort, 0, 0, 0, 0 );
  192.     for ( n = 1; n < 2<<SCRDEPTH; n++ )
  193.         {
  194.         r = RangeRand( 16 - n ) + n;
  195.         g = RangeRand( 16 - n ) + n;
  196.         b = RangeRand( 16 - n ) + n;
  197.         SetRGB4( &scr1->ViewPort, n, r, g, b );
  198.         SetRGB4( &scr2->ViewPort, n, r, g, b );
  199.         }
  200.  
  201.     SetAllFireworks();
  202.  
  203.     while( STILL_BLANKING )
  204.         {
  205.         MoveAllFireworks( activescr );
  206.         activescr = ( activescr == scr1 ? scr2 : scr1 );
  207.         }
  208.  
  209.     SpritesOn();
  210.     }
  211. if ( scr1 )
  212.     CloseScreen( scr1 );
  213. if ( scr2 )
  214.     CloseScreen( scr2 );
  215. if ( !success )
  216.     SendClientMsg( ACTION_FAILED );
  217. }
  218.  
  219. void __main( char *line )
  220. {
  221. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
  222.     {
  223.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
  224.         {
  225.         if ( dinfo = OpenCommunication() )
  226.             {
  227.             RangeSeed = time( NULL );
  228.             Blank();
  229.             CloseCommunication( dinfo );
  230.             }
  231.         CloseLibrary( (struct Library *)GfxBase );
  232.         }
  233.     CloseLibrary( (struct Library *)IntuitionBase );
  234.     }
  235. }
  236.